package businesslogic.Strategybl;

import PO.StrategyPO;
import VO.StrategyVO;
import dao.StrategyDao.StrategyDao;
import dao.StrategyDao._stub.StrategyDao_stub;
import util.Message;
import util.UserType;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 酒店促销策略的具体类，和网站的那个有大量重复
 * Created by insomnia on 2016/10/27.
 */
public class HotelStrategy {
    /**持有一个dao层的引用*/
    private StrategyDao strategyDao;
    /**构造函数*/
    public HotelStrategy(){
        try {
            strategyDao=new StrategyDao_stub();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /***
     * 根据酒店用户名得到酒店的所有的促销策略
     * @param hotelid
     * @return 促销策略的迭代器
     */
    public Iterator<StrategyVO> getStrategy(String hotelid) {
        Iterator<StrategyPO> iter=strategyDao.getStrategy(UserType.HOTELSTAFF,hotelid);//隔壁有问题啊 修改dao层接口
        ArrayList<StrategyVO> list=new ArrayList<StrategyVO>();
        while (iter.hasNext()){
            StrategyItem item=new StrategyItem((StrategyPO)iter.next());
            list.add(item.strategyItemToVo());
        }
        Iterator<StrategyVO> res=list.iterator();
        return res;
    }
    /***
     * 添加新的酒店促销策略
     * @param strategyVO
     * @return 是否成功添加网站策略或出现的错误
     */
    public Message addNewStrategy(StrategyVO strategyVO) {
        StrategyItem item =new StrategyItem(strategyVO);
        if(item.isComplete()){
            StrategyPO strategyPO=item.strategyItemToPo();
            boolean flag=strategyDao.addNewStrategy(strategyPO);
            if(flag){
                return Message.SUCCESS;
            }else{
                return Message.FAIL;
            }
        }else{
            return Message.NOT_COMPLETE;
        }
    }
    /***
     * 添加新的网站促销策略
     * @param strategyVO
     * @return 是否成功添加网站策略或出现的错误
     */
    public boolean removeStrategy(StrategyVO strategyVO) {
        StrategyItem item =new StrategyItem(strategyVO);
        StrategyPO strategyPO=item.strategyItemToPo();
        return strategyDao.removeStrategy(strategyPO);
    }
}
